package com.itheima.controller;

import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.dto.CheckItemDTO;
import com.itheima.pojo.entity.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/checkitem")
public class CheckItemController {

    @Autowired
    private CheckItemService checkItemService;

    @PostMapping("/add")
    public Result addCheckItem(CheckItemDTO checkItemDTO){
        checkItemService.addCheckItem(checkItemDTO);
        return new Result(true,"新增检查项成功");
    }

    @GetMapping("/delete")
    public Result deleteCheckItemById(String id){
        checkItemService.deleteCheckItemById(id);
        return new Result(true,"删除检查项成功");
    }

    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId(String checkgroupId){
        Integer[] array=checkItemService.findCheckItemIdsByCheckGroupId(checkgroupId);
        return new Result(true,"查询检查项成功",array);
    }

    @PostMapping("/edit")
    public Result editCheckItem(@RequestBody CheckItem checkItem){
        checkItemService.editCheckItem(checkItem);
        return new Result(true,"编辑检查项");
    }

    @PostMapping("/findPage")
    public PageResult findPageCheckItem(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult=checkItemService.findPageCheckItem(queryPageBean);
        return pageResult;
    }

    @GetMapping("/findAll")
    public Result findAllCheckItem(){
        Object[] array=checkItemService.findAll();
        return new Result(true,"查询检查项成功",array);
    }

    @GetMapping("/findById")
    public Result findByIdCheckItem(String id){
        Object array=checkItemService.findByIdCheckItem(id);
        return new Result(true,"查询检查项成功",array);
    }

}


